package com;

import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@WebServlet(value = "/ModifyCourse")
public class ModifyCourse extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");

        String tempcid=request.getParameter("c_id");
        String tempname=request.getParameter("c_name");
        String temptid=request.getParameter("t_id");



        //int courseid= Integer.parseInt(request.getParameter("courseid"));
        String courseid=request.getParameter("courseid");
        String name=request.getParameter("coursename");
        //int teacherid= Integer.parseInt(request.getParameter("teacherid"));
        String teacherid=request.getParameter("teacherid");

        Connection con=null;
        PreparedStatement psm=null;
        try {
        con= JdbcUtil.getConnection();
        psm=con.prepareStatement("UPDATE course SET c_id="+courseid+",c_name="+name+",t_id="+teacherid+"where c_id="+tempcid+",c_name="+tempname+",t_id="+temptid);

        } catch (SQLException e) {
            e.printStackTrace();
        }

        request.getRequestDispatcher("/jsp/InsertCourse.jsp").forward(request,response);
    }

}
